<?php
/*
	插件概览
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$return=array();
$basic=$this->plugin_setting('basic');
if($_RQ['op']=='get'){
	//显示统计数据
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$mounthtime =  mktime(0,0,0,date('m'),1,date('Y'));
	if($_RQ['headerno']){
		set_html('header','common/header-no');
		$return['headerno']=$_RQ['headerno'];
	}
	$return['screenurl']=manage_url('jy_order_ping/index//headerno=1');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'deleted'=>0,'realname <>'=>'','mobile <>'=>'');
	$pindex = max(1, intval($_RQ['page']));
	$psize = $basic['num']?:30;
	$total='';
	$fields=array('id','mid','status','address','realname','mobile');
	$getnews=pdo_get('jy_weishop_order',$params,$fields,'id desc');
	if($_RQ['isup']==1){
		if($getnews['id']>$_SESSION['lastid']){
			$_SESSION['lastid']=$getnews['id'];
		}else{
			$res=array(
				'list'=>array(),
				'none'=>1,
			);
			exi($res);
			exit;
		}
	}
	$list=pdo_getslice('jy_weishop_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as &$item){
		$address=json_decode($item['address'],true);
		$item['realname']=$address['name']?:$item['realname'];
		$item['address']=model('core/member')->get_address_str($address);
		$goodsid=pdo_getcolumn('jy_weishop_order_goods',array('orderid'=>$item['id']),'goodsid');
		$item['goodstitle']=pdo_getcolumn('jy_weishop_goods',array('id'=>$goodsid),'title');
		if($basic['is_yin']){
			$item['address']=cfc('tools')->substr($item['address'],0,13).'XXXXXX';
			$sex=pdo_getcolumn('core_members',array('id'=>$item['mid']),'sex');
			if($sex==1){
				$sex='先生';
			}elseif($sex==2){
				$sex='女士';
			}else{
				$sex='XX';
			}
			$item['realname']=cfc('tools')->substr($item['realname'],0,1).$sex;
			$item['mobile']=cfc('tools')->substr($item['mobile'],0,3).'XXXX'.cfc('tools')->substr($item['mobile'],7,4);
		}
	}
	$lastid=$list[0]['id']?:0;
	$_SESSION['lastid']=$lastid;
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='gettanmus'){
	$return=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'deleted'=>0,'id >'=>$_SESSION['lastid']);
	$pindex = 1;
	$psize = 1;
	$total='';
	$fields=array('id','mid','status','address','realname','mobile');
	$list=pdo_getslice('jy_weishop_order',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	foreach($list as &$item){
		$address=json_decode($item['address'],true);
		$item['realname']=$address['name']?:$item['realname'];
		$item['address']=model('core/member')->get_address_str($address);
		$goodsid=pdo_getcolumn('jy_weishop_order_goods',array('orderid'=>$item['id']),'goodsid');
		$item['goodstitle']=pdo_getcolumn('jy_weishop_goods',array('id'=>$goodsid),'title');
		if($basic['is_yin']){
			$item['address']=cfc('tools')->substr($item['address'],0,13).'XXXXXX';
			$sex=pdo_getcolumn('core_members',array('id'=>$item['mid']),'sex');
			if($sex==1){
				$sex='先生';
			}elseif($sex==2){
				$sex='女士';
			}else{
				$sex='XX';
			}
			$item['realname']=cfc('tools')->substr($item['realname'],0,1).$sex;
			$item['mobile']=cfc('tools')->substr($item['mobile'],0,3).'XXXX'.cfc('tools')->substr($item['mobile'],7,4);
		}
		$item['msg']=$item['realname'].'购买了《'.$item['goodstitle'].'》商品！';
	}
	$return['list']=$list;
	//$return['htmlmsg']='<tr class="uhy2"><td class="uiuewry2">'.$list[0]['realname'].'"</td> <td class="uiuewry2">'.$list[0]['mobile'].'</td> <td class="uiuewry2">'.$list[0]['goodstitle'].'</td> <td class="uiuewry2">'.$list[0]['address'].'"</td></tr>';
	$lastid=$list[0]['id'];
	if($lastid){
		$_SESSION['lastid']=$lastid;
	}
	$return['lastid']=$_SESSION['lastid'];
	exi($return);
}